{ 
  open Parser (* parser generated from parser.mly *)
  open Lexing

  let incr_lineno lexbuf =
    let pos = lexbuf.lex_curr_p in
    lexbuf.lex_curr_p <- { pos with
      pos_lnum = pos.pos_lnum + 1;
      pos_bol = pos.pos_cnum
    }
}

rule token = parse
  [' ' '\t'] { token lexbuf }
| '\n' '\r'? | '\r' '\n' { incr_lineno lexbuf; token lexbuf }
| "/*"     { comment lexbuf }           (* Comments *)
| '+' { PLUS }
| '-' { MINUS }
| '*' { TIMES }
| '/' { DIV }
| ';' { SEMI }
| ':' { COLON }
| ',' { COMMA }
| "<<" { LDIRECT }
| ">>" { RDIRECT }
| "=" { EQUALS }
| '^' { POW }
| '.' { DOT }
| '[' { LBRACK }
| ']' { RBRACK }
| '{' { LBRACE }
| '}' { RBRACE }
| '(' { LPAREN }
| ')' { RPAREN }
| "module" { MODULE }
| "size" { SIZE }
| "for" { FOR }
(*| "begin" { BEGIN } *)
| "end" { raise (Failure ("'end' is a reserved for future versions of Synapse.")) }
| "t" { raise (Failure ("'t' is a reserved for future versions of Synapse.")) }
| "pi" { PI }
| "e" { E }
| "sqrt" { SQRT }
| "exp" { EXP }
| "sin" { SIN }
| "cos" { COS }
| "abs" { ABS }
| "kernel" { KERNEL }
| "pragma" { PRAGMA }
| "input" { INPUT }
| "**" { CONV }
| "filter" { FILTER }
| ['a'-'z' 'A'-'Z'] ['a'-'z' 'A'-'Z' '0'-'9' '_']* as lit { ID( lit) }
| '$' ['0'-'9'] as lit { PARAM( int_of_char lit.[1]-48) }
| ['0'-'9']+ as lit { INT(int_of_string lit) }
| (['0'-'9']+ '.' ['0'-'9']* | ['0'-'9']* '.' ['0'-'9']+ ) 
    as lit { FLOAT(float_of_string lit) }
| eof { EOF }
| _ as char { raise (Failure("illegal character " ^ Char.escaped char)) }

and comment = parse
  "*/" { token lexbuf }
| _    { comment lexbuf }
